import React, { useState} from 'react'
import { AutoComplete } from 'antd';
import { selectTeacher } from './service';

interface Select2Props {
  url: string
}

const Select2: React.FC<Select2Props> = (props) => {
  const { url } = props
  const [options, setOptions] = useState<{ value: string }[]>([]);
  const [id, setId] = useState<boolean>(false)
  const onSelect = (data: any, option: any) => {
    setId(option.id)
  };
  const onSearch = async (keys: string) => {
    let data = await selectTeacher({ keys })
    let options = !keys ? [] : data.result.map((item: { Uid: any; Name: any; }) => ({id: item.Uid, label: item.Name, value: item.Name}))
    setOptions(options);
  };

  return (
    <>
      <AutoComplete
        options={options}
        onSelect={onSelect}
        onSearch={onSearch}
        placeholder="请选择"
        style={{width:'1000px'}}
        />
    </>
  )
}

export default Select2
